<include file="Public/header"/>
<include file="Public/menu"/>
<style>
	button.cm { float: right; margin-left: 5px }
</style>
<div class="page-content">
	<div class="page-header">
		<h1>
			分类
			<small>
				<i class="icon-double-angle-right"></i>
				浏览分类
			</small>
		</h1>
	</div>
	<!-- /.page-header -->
	<!-- PAGE CONTENT BEGINS -->
	<div class="row">
		<div class="col-xs-12">

			<div class="row">
				<div class="tabbable">
					<ul class="nav nav-tabs" id="myTab">
						<li class="active">
							<a>
								<i class="green icon-home bigger-110"></i>
								浏览分类
							</a>
						</li>
						<li>
							<a href="{:U('/Admin/Category/add')}">
								<i class="green icon-edit bigger-110"></i>
								添加分类
							</a>
						</li>
					</ul>
					<div class="tab-content" style="font-size: 14px">
						<div class="row">
							<div class="col-sm-6">
								<div class="tabbable tabs-right">
									<ul class="nav nav-tabs" id="myTab3">
										<li class="active">
										<a href="#">
											全部
										</a>
										</li>
										<!-- <li>
											<a href="#">
												职位												
												<span class="badge badge-danger">208</span>
											</a>
											</li><li>
											<a href="#">
												新闻												
												<span class="badge badge-danger">4</span>
											</a>
											</li> -->
										</ul>
									<div class="tab-content">
										<div id="home3" class="tab-pane in active">
										    <div id="tree" class="tree tree-unselectable">
											        <div class="tree-folder-content">
											        	
											        </div>
											      <div class="tree-folder" style="display: block;">
											          <div class="tree-folder-header">
												          <div class="tree-folder-name">分类加载中...
												             <span data-id="2"></span>
												          </div>
											          </div>
											     </div>
										     </div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
	<!-- PAGE CONTENT END -->
<script>
function del(id){
	bootbox.confirm('确定删除吗?',function(res){
		if(res){
			$.ajax({
					url : "/Admin/Category/del/id/" + id,
					type : "get",
					dataType : "json",
					async : false,
					success : function (msg) {
						if(msg.status == 1){
							bootbox.alert({
								message : msg.info ,
								title : '通知信息:'
							});
							window.location.href = location.href;
						}else{
							bootbox.alert({
								message : msg.info ,
								title : '通知信息:'
							});
						}
					}
				});
			}
	});
	
}

function togga(id){
	//点击哪个分类设置隐藏或者显示
	$('.toga'+id).toggle( "fold" );
	//点击主分类设置子分类为隐藏
	$('.togb').css('display','none');
}
function toggb(id){
	$('.togb'+id).toggle( "fold" );
}

seajs.use(['$', 'bootbox', 'fuelux-tree', 'ace-elements'], function ($) {
		var tree_data = {};
		//从服务器端获取分类树
		$.ajax({
			url : "/Admin/Category/getTree",
			dataType : "json",
			type : "get",
			async : false,
			success : function (data) {
				if ( data ) {
					tree_data = data;
				}
			}
		});

		var htmls = '';
		var togga = 0;
		var toggb = 0;
		for(var i =0;i<tree_data.length;i++){
			if(tree_data[i]['lev'] == 0){
				togga++;	
				htmls += '<div class="tree-folder" style="display: block;"><div class="tree-folder-header"><div class="tree-folder-name" ><span onclick="javascript:togga('+togga+')">'+tree_data[i]['cat_name']+'</span><span data-id="2" style="display:block;float:right;"><a href="/Admin/Category/edit/id/'+tree_data[i]['cat_id']+'">编辑</a>&nbsp;&nbsp;&nbsp;<a href="javascript:del('+tree_data[i]['cat_id']+')">删除</a></span></div></div></div>';
			}else if(tree_data[i]['lev'] == 1){	
				toggb++;
				htmls += '<div style="display: none;cursor:pointer;" class="toga toga'+ togga +'"><div class="tree-folder-header"><div class="tree-folder-name" style="margin-left:35px;"><span  onclick="javascript:toggb('+toggb+')">'+tree_data[i]['cat_name']+'</span><span data-id="2" style="display:block;float:right;padding-right:6px;"><a href="/Admin/Category/edit/id/'+tree_data[i]['cat_id']+'">编辑</a>&nbsp;&nbsp;&nbsp;<a href="javascript:del('+tree_data[i]['cat_id']+')">删除</a></span></div></div></div>';
			}else if (tree_data[i]['lev'] == 2){
				htmls += '<div style="display: none;" class="togb togb'+ toggb +'"><div class="tree-folder-header"><div class="tree-folder-name" style="margin-left:50px;color:gray;">'+tree_data[i]['cat_name']+'<span data-id="2" style="display:block;float:right;padding-right:6px;"><a href="/Admin/Category/edit/id/'+tree_data[i]['cat_id']+'">编辑</a>&nbsp;&nbsp;&nbsp;<a href="javascript:del('+tree_data[i]['cat_id']+')">删除</a></span></div></div></div>';	
			}
		}
		$('#tree').html(htmls);


})	
</script>
<include file="Public/footer"/>

